<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Grafik extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->helper('flexigrid');
        $this->load->library('flexigrid');
		$this->load->library('session');
        $this->load->model('batch_model');
        $this->load->model('lisensi_model');
        $this->load->model('grafik_model');
		$this->load->library('form_validation');
		$this->cek_login();
    }

	
	function cek_login(){
		$id_hak = $this->session->userdata('id_hak');
		if($id_hak < 1 || $id_hak > 2 || $id_hak == ''){
			redirect ('login');
		}
		
	}
	

	function index()
	{
		$this->load->helper(array('url','fusioncharts')) ;
		
        $graph_swfFile      = base_url().'public/flash/Column3D.swf' ;
        $graph_caption      = 'Grafik Jumlah Peserta Tiap Lisensi';
        $graph_numberPrefix = ' Peserta' ;
        $graph_title        = 'Jumlah Peserta' ;
        $graph_width        = 700 ;
        $graph_height       = 350 ;

		//get data
		$a=0;
		$jumlah = $this->grafik_model->jumlah_peserta_perlisensi();
        foreach ($jumlah->result() as $row) {
            $arrData[$a][1] = $row->NAMA_LISENSI;
			$arrData[$a][2] = $row->HASIL;
			$a++;
			
        }
		
        
        $strXML = "<graph caption='".$graph_caption."' xAxisName='Nama Lisensi' yAxisName='Jumlah Peserta' numberSuffix='".$graph_numberPrefix."' formatNumberScale='0' decimalPrecision='0'>";

        //Convert data to XML and append
		foreach ($arrData as $arSubData)
		{
				$strXML .= "<set name='" . $arSubData[1] . "' value='" . $arSubData[2] . "' color='".getFCColor()."' />";
		}
		//Close <chart> element
		$strXML .= "</graph>";
        
        $data['graph']  = renderChart($graph_swfFile, $graph_title, $strXML, "div" , $graph_width, $graph_height);

	
		$data['title'] = 'Grafik';
        $this->template->write_view('content', 'grafik/grafik', $data);
        $this->template->render();
	}
	
	
	
	function pertumbuhan_peserta()
	{
		$id_lisensi = $this->input->post('id_lisensi');
		$this->load->helper(array('url','fusioncharts')) ;
		
        $graph_swfFile      = base_url().'public/flash/Column3D.swf' ;
        $graph_caption      = 'Grafik Pertumbuhan Peserta Pelatihan';
        $graph_numberPrefix = ' Peserta' ;
        $graph_title        = 'Jumlah Peserta' ;
        $graph_width        = 700 ;
        $graph_height       = 350 ;

		//get data
		$tahun_sekarang = date('Y');
		$tahun_akhir = $tahun_sekarang-5;;
		$a=0;
		// $jumlah = $this->grafik_model->pertumbuhan_peserta($id_lisensi);
		
		while ($tahun_akhir <= $tahun_sekarang){
			$jumlah = $this->grafik_model->pertumbuhan_peserta($tahun_akhir, $id_lisensi);
			foreach ($jumlah->result() as $row) {
				$arrData[$a][1] = $tahun_akhir;
				$arrData[$a][2] = $row->HASIL;
			}
			$tahun_akhir++;
			$a++;
		}
        // foreach ($jumlah->result() as $row) {
            // $arrData[$a][1] = $row->TAHUN;
			// $arrData[$a][2] = $row->HASIL;
			// $a++;
			
        // }
		
		
        
        $strXML = "<graph caption='".$graph_caption."' xAxisName='Tahun' yAxisName='Jumlah Peserta' numberSuffix='".$graph_numberPrefix."' formatNumberScale='0' decimalPrecision='0'>";

        //Convert data to XML and append
		foreach ($arrData as $arSubData)
		{
				$strXML .= "<set name='" . $arSubData[1] . "' value='" . $arSubData[2] . "' color='".getFCColor()."' />";
		}
		//Close <chart> element
		$strXML .= "</graph>";
        
        $data['graph']  = renderChart($graph_swfFile, $graph_title, $strXML, "div" , $graph_width, $graph_height);

		$data['status'] = 'new';
		$data['id_lisensi'] = $id_lisensi;
		$data['lisensi'] = $this->lisensi_model->get_all_lisensi();
		$data['title'] = 'Grafik';
        $this->template->write_view('content', 'grafik/form_grafik_pertumbuhan', $data);
        $this->template->render();
	}
	
	
	
	function profesi()
	{
		$id_lisensi = $this->input->post('id_lisensi');
		$this->load->helper(array('url','fusioncharts')) ;
		
        $graph_swfFile      = base_url().'public/flash/Column3D.swf' ;
        $graph_caption      = 'Grafik Peserta Pelatihan Berdasarkan Profesi';
        $graph_numberPrefix = ' Peserta' ;
        $graph_title        = 'Jumlah Peserta' ;
        $graph_width        = 700 ;
        $graph_height       = 350 ;

		//get data
		$a=0;
		$jumlah = $this->grafik_model->peserta_per_pekerjaan($id_lisensi);
        foreach ($jumlah->result() as $row) {
            $arrData[$a][1] = $row->PEKERJAAN;
			$arrData[$a][2] = $row->HASIL;
			$a++;
			
        }
		
		
        
        $strXML = "<graph caption='".$graph_caption."' xAxisName='Profesi' yAxisName='Jumlah Peserta' numberSuffix='".$graph_numberPrefix."' formatNumberScale='0' decimalPrecision='0'>";

        //Convert data to XML and append
		foreach ($arrData as $arSubData)
		{
				$strXML .= "<set name='" . $arSubData[1] . "' value='" . $arSubData[2] . "' color='".getFCColor()."' />";
		}
		//Close <chart> element
		$strXML .= "</graph>";
        
        $data['graph']  = renderChart($graph_swfFile, $graph_title, $strXML, "div" , $graph_width, $graph_height);

		$data['status'] = 'new';
		$data['id_lisensi'] = $id_lisensi;
		$data['lisensi'] = $this->lisensi_model->get_all_lisensi();
		$data['title'] = 'Grafik';
        $this->template->write_view('content', 'grafik/form_grafik_profesi', $data);
        $this->template->render();
	}
	
	
	function jenis_kelamin()
	{
		$id_lisensi = $this->input->post('id_lisensi');
		$this->load->helper(array('url','fusioncharts')) ;
		
        $graph_swfFile      = base_url().'public/flash/Column3D.swf' ;
        $graph_caption      = 'Grafik Peserta Pelatihan Berdasarkan Jenis Kelamin';
        $graph_numberPrefix = ' Peserta' ;
        $graph_title        = 'Jumlah Peserta' ;
        $graph_width        = 700 ;
        $graph_height       = 350 ;

		//get data
		$a=0;
		$jumlah = $this->grafik_model->peserta_per_jenkel($id_lisensi);
        foreach ($jumlah->result() as $row) {
            $arrData[$a][1] = $row->JENIS_KELAMIN;
			$arrData[$a][2] = $row->HASIL;
			$a++;
			
        }
		
		
        
        $strXML = "<graph caption='".$graph_caption."' xAxisName='Jenis Kelamin' yAxisName='Jumlah Peserta' numberSuffix='".$graph_numberPrefix."' formatNumberScale='0' decimalPrecision='0'>";

        //Convert data to XML and append
		foreach ($arrData as $arSubData)
		{
				$strXML .= "<set name='" . $arSubData[1] . "' value='" . $arSubData[2] . "' color='".getFCColor()."' />";
		}
		//Close <chart> element
		$strXML .= "</graph>";
        
        $data['graph']  = renderChart($graph_swfFile, $graph_title, $strXML, "div" , $graph_width, $graph_height);

		$data['status'] = 'new';
		$data['id_lisensi'] = $id_lisensi;
		$data['lisensi'] = $this->lisensi_model->get_all_lisensi();
		$data['title'] = 'Grafik';
        $this->template->write_view('content', 'grafik/form_grafik_jk', $data);
        $this->template->render();
	}
	
}

/* End of file pegawai.php */
/* Location: ./application/controllers/pegawai.php */